<template>
  <div class="static">
    <div class="flex flex-a-c headerBox" @click="gotoThat">
      <div class="title">状态统计</div>
      <a-icon type="right" />
    </div>
    <div class="lightBox">
      <!--              环形图-->
      <div style="width: 60%;float: left;">
        <pieCharts :chartData="pieData" />
      </div>
      <!--              环形图图例-->
      <div style="width: 40%;float: left;" class="pielegendbox">
        <p class="pielegend" v-for="(item, index) in pieData" :key="index">
          <span
            class="quan"
            :style="{ 'border-color': alarmStatues[index] }"
          ></span>
          <span class="name">{{ item.name }}</span>
          <span class="value">{{ item.string }}</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import pieCharts from "./pieCharts.vue";
export default {
  name: "index",

  components: {
    pieCharts
  },
  props: {
    alarmStatues: {
      type: Array,
      default: () => ["#3FC529", "#FBC225", "#E74629", "#E2E7EE"]
    },
    SumStateTimeList: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    SumStateTimeList(val) {
      this.SumStateTime(val);
    }
  },
  data() {
    let moment = this.$Moment;
    return {
      userName: "",
      name: "",
      role: "",
      compId: "",
      dateType: 1,
      pieData: []
    };
  },
  methods: {
    gotoThat() {
      this.$store.commit("board/HeadNavType", 2);
      localStorage.setItem("navType", 2);
      this.$router.push("/statistics");
    },
    SumStateTime(val) {
      this.pieData = [
        {
          value: (val.running * 100).toFixed(2),
          name: "运行",
          string: val.runningStr
        },
        {
          value: (val.stop * 100).toFixed(2),
          name: "待机",
          string: val.stopStr
        },
        {
          value: (val.alarm * 100).toFixed(2),
          name: "报警",
          string: val.alarmStr
        },
        {
          value: (val.offline * 100).toFixed(2),
          name: "离线",
          string: val.offlineStr
        }
      ];
    }
  }
};
</script>

<style scoped lang="less">
.headerBox {
  margin: 20px 0 10px 0;
  .title {
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin: 0 4px 0 0;
  }
}
.static {
  width: 100%;
  .lightBox {
    width: 100%;
    background-color: #fff;
    border-radius: 6px;
    overflow: hidden;
  }
}
</style>
